class_name StatsSrc
extends Resource

signal statsChanged

@export var maxHealth:=1
@export var skin:Texture

var health:int: set=setHealth
var armor:int:set=setArmor

func init():
    health=maxHealth
    armor=0

func setHealth(value:int)->void:
    health=clampi(value,0,maxHealth)
    statsChanged.emit()

func setArmor(value:int)->void:
    armor=clampi(value,0,999)
    statsChanged.emit()

func getHurt(hurt:int)->void:
    if hurt<=0:return
    var damage=clampi(hurt-armor,0,hurt)
    self.armor=clampi(armor-hurt,0,armor)
    self.health-=damage

func heal(amount:int)->void:
    self.health+=amount

func instance()->Resource:
    var stats:StatsSrc=duplicate()
    stats.init()
    return stats
